/***************************************************************************
 * Open Object Oriented ANSI C                                             *
 ***************************************************************************
 * Code given under the terms of GNU General Public Licence (GPLv3)        *
 * and without any waranties of any kind including but not limitative to   *
 * waranties on merchandability or any particular applications fitness.    *
 * For more information on GNU/GPL go on :                                 *
 * "http://www.gnu.org/copyleft/gpl.html"                                  *
 *                                                                         *
 * You are allowed to use it for any purposes in the terms of GNU/GPLv3    *
 * (or more).                                                              *
 * This text MUST stay in state on copyed sources (or sources using it)    *
 * and must not be altered.                                                *
 * You are allowed to add your name at the end of the Copylefs list.       *
 ***************************************************************************
 * Copylefts List :                                                        *
 ***************************************************************************
 * 2010-03-20 Patrick PIGNOL <pignol_patrick@hotmail.com> (Original)       *
 * (Type your name here if needed)                                         *
 ***************************************************************************/
#ifndef CLASS_H_INCLUDED
#define CLASS_H_INCLUDED

#define CLASS_TYPEID 0

typedef struct ClassVirtualTable ClassVirtualTable;
typedef struct ClassInterface ClassInterface;
typedef struct Class Class;

#include <stdlib.h>
#include <stdarg.h>
#include "Bool.h"

struct ClassVirtualTable
{
    unsigned long int TypeID;
    ClassInterface* Interface;
    ClassVirtualTable* AncestorTable;
    unsigned long int ReferenceCount;
    Class* (*new)(unsigned long, va_list*);
    ClassVirtualTable* (*Initialize)(Class* this, unsigned long, va_list*);
    void (*Garbage)(Class* this);
    unsigned long int (*TypeOf)(Class* this);
    bool (*IsSameTypeThanTypeID)(Class* this, unsigned long int pTypeID);
    bool (*IsKindOfTypeID)(Class* this, unsigned long int pTypeID);
    bool (*IsSameTypeThan)(Class* this, Class* pSource);
    bool (*IsKindOf)(Class* this, Class* pSource);
};

struct ClassInterface
{
    void (*Constructor)(Class* this, unsigned long int pArgsCount, va_list* pParameters); /* Constructor pointer of object. Called by Initialise(). */
    void (*Destructor)(Class* this); /* Destructor pointer of object. Called by Garbage(). */
    Class* (*Clone)(Class* this);
};

struct Class
{
    ClassVirtualTable* VirtualTable;
    void (*Constructor)(Class* this, unsigned long int pArgsCount, va_list* pParameters);
    void (*Destructor)(Class* this);
    Class* (*Clone)(Class* this);
};

Class* ClassNew(unsigned long pArgsCount, va_list* pParameters);
ClassVirtualTable* ClassInitialize(Class* this, unsigned long pArgsCount, va_list* pParameters);
void ClassGarbage(Class* this);
unsigned long int ClassTypeOf(Class* this);

bool ClassIsSameTypeThanTypeID(Class* this, unsigned long int pTypeID);
bool ClassIsKindOfTypeID(Class* this, unsigned long int pTypeID);
bool ClassIsSameTypeThan(Class* this, Class* pSource);
bool ClassIsKindOf(Class* this, Class* pSource);

void ClassConstructor(Class* this, unsigned long int pArgsCount, va_list* pParameters);
void ClassDestructor(Class* this);
Class* ClassClone(Class* this);

#endif /* CLASS_H_INCLUDED */
